package com.sm.controller;

import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaMode;
import com.github.pagehelper.PageInfo;
import com.sm.controller.request.CancelCourseReq;
import com.sm.controller.request.SelectCourseRequest;
import com.sm.controller.request.StudentRegisterReq;
import com.sm.controller.request.UpdateProfileRequest;
import com.sm.entity.Course;
import com.sm.entity.CourseScore;
import com.sm.service.UserService;
import com.sm.utils.R;
import com.sm.service.StudentService;
import com.sm.utils.RD;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Cola
 * @description
 * @date 2022/1/30
 */
@RestController
public class StudentController {

    @Resource
    UserService userService;

    @Resource
    StudentService studentService;

    /**
    * @author cola
    * @description 更新学生用户的个人信息
    * @date 2022/2/4
    */
    @PostMapping("/student/update/profile")
    @SaCheckRole("student")
    R updateProfile(@RequestBody UpdateProfileRequest updateProfileRequest) throws Exception {
        studentService.updateProfile(updateProfileRequest);
        return R.success();
    }

    /**
    * @author cola
    * @description 学生用户查看课程列表
    * @date 2022/2/13
    */
    @GetMapping("/student/course/select/list")
    RD getCourseListForSelect(@RequestParam("page") Integer page, @RequestParam("size") Integer size){
        PageInfo<Course> list = studentService.getCourseListForSelect(page,size);
        return RD.success ().putData("list",list.getList()).putData("total",list.getTotal());
    }

    /**
    * @author cola
    * @description 学生查看已选课程列表
    * @date 2022/3/3
    */
    @GetMapping("/student/course/selected/list")
    RD getSelectedCourseList(@RequestParam("page") Integer page, @RequestParam("size") Integer size){
        List<Course> list = studentService.getSelectedCourseList(page,size);
        int total = studentService.getSelectedCoursesNum();
        return RD.success().putData("list",list).putData("total",total);
    }

    /**
    * @author cola
    * @description 学生选课
    * @date 2022/2/13
    */
    @PostMapping("/student/course/select")
    @SaCheckRole("student")
    R selectCourse(@RequestBody SelectCourseRequest selectCourseRequest) throws Exception {
        studentService.selectCourse(selectCourseRequest);
        return R.success();
    }

    /**
    * @author cola
    * @description 学生退课
    * @date 2022/3/3
    */
    @PostMapping("/student/course/cancel")
    R cancelSelectCourse(@RequestBody CancelCourseReq req) throws Exception {
        studentService.cancelSelectCourse(req);
        return R.success();
    }

    /**
    * @author cola
    * @description 获取学生各课程成绩
    * @date 2022/3/4
    */
    @GetMapping("/student/course/scores")
    RD getCourseScores(){
        List<CourseScore> list = studentService.getCourseScores();
        int total = studentService.getSelectedCoursesNum();
        return RD.success().putData("list",list).putData("total",total);
    }

    /**
    * @author cola
    * @description 注册学生账号
    * @date 2022/3/8
    */
    @RequestMapping("/student/register")
    R studentRegister(@RequestBody StudentRegisterReq req) throws Exception {
        studentService.studentRegister(req);
        return R.success();
    }

    /**
    * @author cola
    * @description 学生账号注销
    * @date 2022/3/10
    */
    @RequestMapping("/student/account/delete")
    R deleteStuAccount() throws Exception {
        studentService.deleteStuAccount();
        return R.success();
    }
}
